LanguageExt.Core

LanguageExt.Core Traits

Contents

Sub modules

Alternative
Applicative
Domain
Eq
Foldable
Functor
Has
Hashable
Monads
Monoid
MonoidK
Mutates
Ord
Range
Reader
Reads
Resolve
Resource
SemiAlternative
Semigroup
SemigroupK
State
Traversable
Writer

interface K <in F, A> Source #

Arrow kind: * -> * used to represent higher-kinded types.

K<F, A> should be thought of as F<A> (where both F an A are parametric). It currently can't be represented in C#, so this allows us to define higher-kinded types and pass them around. We can then build traits that expected a K where the trait is tied to the F.

For example:

K<F, A> where F : Functor<F>
K<M, A> where M : Monad<F>

That means we can write generic functions that work with monads, functors, etc.

Parameters

type F

Trait type

type A

Bound value type

class KExtensions Source #

Methods

method K<F, A> Kind <F, A> (this K<F, A> fa) Source #

Get the base kind type. Avoids casts mid-expression

method FA SafeCast <FA, F, A> (this K<F, A> fa) Source #

where FA : K<F, A>
where F : Functor<F>

method K<M, K<N, A>> KindT <M, N, NA, A> (this K<M, NA> mna) Source #

where NA : K<N, A>
where M : Functor<M>

KindT converts a nested Kind type (inherits K<M, A>), where the inner type is a concrete type and not K<N, A> to the more general version - which allows the other T variant methods to work seamlessly.

The casting of nested types is especially problematic for C#'s type-system, so even though this isn't ideal, it does allow for a truly generic system of working with any nested types as long as there's a Functor implementation for the outer type.

Parameters

type M

Outer functor trait (i.e. Seq)

type N

Inner trait (i.e. Option)

type NA

Concrete nested type (i.e. Option<int>)

type A

Concrete bound value type (i.e. int)

param mna

Nested functor value

returns

More general version of the type that can be used with other T extensions, like BindT

Examples

var mx = Seq<Option>(Some(1), Some(2), Some(3));

var ma = mx.KindT<Seq, Option, Option, int>() .BindT(a => Some(a + 1)) .MapT(a => a + 1); .AsT<Seq, Option, Option, int>();

method K<M, NA> AsT <M, N, NA, A> (this K<M, K<N, A>> mna) Source #

where NA : K<N, A>
where M : Functor<M>

AsT converts a nested Kind type (inherits K<M, A>), where the inner type is a general type (K<N, A>) to its downcast concrete version.

The casting of nested types is especially problematic for C#'s type-system, so even though this isn't ideal, it does allow for a truly generic system of working with any nested types as long as there's a Functor implementation for the outer type.

Parameters

type M

Outer functor trait (i.e. Seq)

type N

Inner trait (i.e. Option)

type NA

Concrete nested type (i.e. Option<int>)

type A

Concrete nested-monad bound value type (i.e. int)

param mna

Nested functor value

returns

Concrete version of the general type.

Examples

var mx = Seq<Option>(Some(1), Some(2), Some(3));

var ma = mx.KindT<Seq, Option, Option, int>() .BindT(a => Some(a + 1)) .MapT(a => a + 1); .AsT<Seq, Option, Option, int>();